package com.pubinfo.passbook.api.controller.auth;

import com.pubinfo.passbook.api.eip.UserInfoService;
import com.pubinfo.passbook.common.entity.TRuleParam;
import com.pubinfo.passbook.common.model.dto.rule.RuleParam;
import com.pubinfo.passbook.common.model.vo.base.JsonResult;
import com.pubinfo.passbook.common.model.vo.base.MyPage;
import com.pubinfo.passbook.common.service.master.TRuleParamService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping(value = "param/manager")
@Api(tags = "审核规则参数集")
public class TParamController {
  
  @Resource
  private TRuleParamService paramService;
  
  @Autowired
  UserInfoService userInfoService;
  
  @PostMapping(value = "save")
  @ApiModelProperty(value = "新增规则参数集")
  public JsonResult<Boolean> saveRuleParam(@RequestBody TRuleParam ruleParam) {
    return JsonResult.success(paramService.saveRuleParam(ruleParam, userInfoService.getCurrentUserInfo(), userInfoService.getRoleInfo()));
  }
  
  @PostMapping("select")
  @ApiModelProperty(value = "查询规则参数集")
  public JsonResult<MyPage<TRuleParam>> selectRuleParam(@RequestBody RuleParam param) {
    return JsonResult.success(new MyPage(paramService.selectRuleParam(param, userInfoService.getCurrentUserInfo(), userInfoService.getRoleInfo())));
  }
  
  @DeleteMapping("remove")
  @ApiModelProperty(value = "删除规则参数集")
  public JsonResult<String> removeRuleParam(String id) {
    return paramService.removeRuleParam(id, userInfoService.getCurrentUserInfo(), userInfoService.getRoleInfo());
  }
  
  @PostMapping("update")
  @ApiModelProperty(value = "修改规则参数集")
  public JsonResult<Boolean> updateRuleParam(@RequestBody TRuleParam ruleParam) {
    return JsonResult.success(paramService.updateRuleParam(ruleParam, userInfoService.getCurrentUserInfo(), userInfoService.getRoleInfo()));
  }
}
